package com.cby.widget.sample.bubblenavigation

import android.graphics.Typeface
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.cby.widget.sample.R
import com.cby.widget.sample.databinding.ActivityBubbleNavFloatTopBarBinding
import com.cby.widget.sample.ext.binding
import com.cby.widget.sample.fragments.ScreenSlidePageFragment

/**
 * @description: BubbleNavFloatTopBarActivity
 *
 * @author ChenBaoyang
 * @date 2021/10/16 16:16
 */
class BubbleNavFloatTopBarActivity : AppCompatActivity() {

    private val binding: ActivityBubbleNavFloatTopBarBinding by binding()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding.floatingTopBarNavigation.setTypeface(Typeface.createFromAsset(assets, "rubik.ttf"))
        binding.floatingTopBarNavigation.setBadgeValue(0, "3")
        binding.floatingTopBarNavigation.setBadgeValue(1, "9+") //invisible badge

        val fragList = ArrayList<ScreenSlidePageFragment>()
        fragList.add(ScreenSlidePageFragment.newInstance(getString(R.string.home), R.color.red_inactive))
        fragList.add(ScreenSlidePageFragment.newInstance(getString(R.string.search), R.color.blue_inactive))
        fragList.add(ScreenSlidePageFragment.newInstance(getString(R.string.likes), R.color.blue_grey_inactive))
        fragList.add(ScreenSlidePageFragment.newInstance(getString(R.string.notification), R.color.green_inactive))
        val pagerAdapter = ScreenSlidePagerAdapter(fragList, supportFragmentManager)
        binding.viewPager.adapter = pagerAdapter
        //disable swipe
        binding.viewPager.setOnTouchListener { _, _ ->
            return@setOnTouchListener true
        }


        binding.floatingTopBarNavigation.setNavigationChangeListener { _, position ->
            binding.viewPager.setCurrentItem(position, true)
        }
    }
}